package com.collectplus.express.passport;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;

import com.collectplus.express.R;

/**
 * 带渐变背景
 * 
 * @author coffee<br>
 *         2017-1-5下午2:58:08
 */
public class GradientShape extends GradientDrawable {

	private int color11;// 空白、渐变色
	private int color12;//
	private int color21;// 柜子、渐变色
	private int color22;// end
	private int color31;// 驿站、渐变色
	private int color32;// end
	private int color41;// 新版本
	private int color42;

	public GradientShape(Context context) {
		color11 = Color.parseColor("#E2E3E4");
		color12 = Color.parseColor("#EDEDED");
		color21 = context.getResources().getColor(R.color.passport_21);
		color22 = context.getResources().getColor(R.color.passport_22);
		color31 = context.getResources().getColor(R.color.passport_31);
		color32 = context.getResources().getColor(R.color.passport_32);
		color41 = context.getResources().getColor(R.color.passport_41);
		color42 = context.getResources().getColor(R.color.passport_42);
	}

	/**
	 * 
	 * @param position
	 *            0,1,2代表左中右<br>
	 *            值不同, 四个角的raduis也不同
	 * @param type
	 *            0空白,1柜子,2驿站<br>
	 *            填充的颜色
	 */
	@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
	public void setStyle(int position, int type) {
		// 设置角度
		if (position == 0) {
			setCornerRadii(new float[] { 45, 45, 0, 0, 0, 0, 45, 45 });
		} else if (position == 2) {
			setCornerRadii(new float[] { 0, 0, 45, 45, 45, 45, 0, 0 });
		} else {
			setCornerRadius(0);
		}
		// 16以上才支持渐变
		if (Build.VERSION.SDK_INT > 15) {
			mutate();
			setGradientType(GradientDrawable.LINEAR_GRADIENT);// 线性渐变
			setOrientation(Orientation.TOP_BOTTOM);// 渐变方向
			setColors(getColotByType(type));// 设置渐变颜色
		} else {
			// setColor(argb)
		}
	}

	/**
	 * @param type
	 *            0空白,1柜子,2驿站,3上门<br>
	 * @return
	 */
	public int[] getColotByType(int type) {
//		if (type == 1) {
//			return new int[] { color21, color22 };
//		} else if (type == 2) {
//			return new int[] { color31, color32 };
//		} else {
//			return new int[] { color41, color42 };
//		}
		//火箭侠上门的时候颜色条都改为41和42
		if(type == 0){
			return new int[] { color11, color12 };
		}else {
			return new int[] { color41, color42 };
		}
	}

	/**
	 * 填充色
	 */
	@Override
	public void setColor(int argb) {
		super.setColor(argb);
	}

}
